package com.shiguiwu.springmybatis.designpattern.abstractfactory.scene.factory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @description: 代理
 * @author: stone
 * @date: Created by 2021/8/12 23:23
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.abstractfactory.scene.factory
 */
public class JDKInvocationHandler implements InvocationHandler {

    private ICacheAdapter cacheAdapter;

    public JDKInvocationHandler(ICacheAdapter cacheAdapter) {
        this.cacheAdapter = cacheAdapter;
    }
    //反射调用方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return ICacheAdapter.class.getMethod(method.getName(), MyClassLoaderUtil.getClazzByArgs(args)).invoke(cacheAdapter, args);
    }
}
